/**
 * 
 */
package com.zhanggz.mypattern.proxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author alex
 * @Date Jun 27, 2015
 */
public class TimerHandler implements InvocationHandler {
	
	private Object target;
	
	/**
	 * @param target
	 */
	public TimerHandler(Object target) {
		super();
		this.target = target;
	}



	/* (non-Javadoc)
	 * @see com.zhanggz.mypattern.proxy.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method)
	 */
	@Override
	public void invoke(Object o, Method m) {

		try {
			long starttime = System.currentTimeMillis();
			System.out.println("汽车开始行驶。。。");

			m.invoke(target);

			long endtime = System.currentTimeMillis();
			System.out.println("汽车结束行驶。。。汽车行驶时间：" + (endtime - starttime) + "毫秒！");
		} catch (IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			e.printStackTrace();
		}
	}

}
